<template>
  <el-container class="home-container">
    <!--头部区域-->
    <el-header>
      <!--logo和标题-->
      <div>
        <img src="../../assets/mylogo.png" style="margin-left:-15px;width:200px;">
        <span style="margin-left: 10px;">毕业论文管理系统</span>
      </div>
      <!--退出按钮-->
      <div>
        <el-dropdown>
          <span class="el-dropdown-link" style="cursor: pointer;">
            <span class="name">{{username}}</span>
          </span>
          <el-dropdown-menu slot="dropdown"> 
            <el-dropdown-item icon="el-icon-switch-button" @click.native="logoutUser">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <!--主体区域-->
    <el-container>
      <!--侧边栏-->
      <el-aside :width="isMenuCollapsed ? '100px' : '200px'">
        <!--控制菜单折叠--> 
        <div style="" class="toggle-button el-icon-user-solid"  @click="toggleCollapse">管理员</div>
        <!--菜单列表-->
        <el-menu router
          :collapse="isMenuCollapsed"
          :collapse-transition="false"
          unique-opened 
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409BFF"
          :default-active="activePath">
          <!--一级菜单-->
          <el-submenu :index="String(menu.id)" v-for="menu in menuList" :key="menu.id">
            <template slot="title">
              <!-- 图标 -->
              <i :class="menu.icon"></i>
              <!-- 名称 -->
              <span>{{menu.title}}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item
              :index="submenu.path"
              v-for="submenu in menu.children"
              :key="submenu.id"
              @click="saveActivePath(submenu.path)">
              <template slot="title"> 
                <!-- 名称 -->
                <span style="padding-left:10%">{{submenu.title}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!--内容区域-->
      <el-main>
        <!--路由占位符 原始-->
        <router-view></router-view> 
      </el-main> 
      <BaseFooter /> 
    </el-container>
  </el-container>
</template>

<script>  
  import BaseFooter from '../BaseFooter.vue'
  export default {
    name: 'Admin', 
    components:{BaseFooter},
    data () {
      return {
        draweInfo: false, // 控制个人信息的 显示/隐藏 
        isMenuCollapsed: false,
        // 菜单列表
        menuList: [
          {id:61090000, title: '首页管理', icon: 'el-icon-menu', children:[
            {id:'0001', path : '/admin/notices', title :'公告管理' } 
          ]},
          {id:61090001, title: '学院管理', icon: 'el-icon-s-shop', children:[
            {id:'1000', path : '/admin/college', title :'学院及领导设置' }
          ]},
          {id:61090002, title: '专业管理', icon: 'el-icon-cpu', children:[
            {id:'1000', path : '/admin/time', title :'毕设时间设置' },
            {id:'1001', path : '/admin/dept/teacher', title :'教师信息管理' },
            {id:'1002', path : '/admin/dept/student', title :'学生信息管理' } 
          ]},
          {id:61090003, title: '账号管理', icon: 'el-icon-user-solid', children:[
            {id:'1000', path : '/admin/user', title :'人员账号设置' } 
          ]}
        ],  
        activePath: '', // 当前激活菜单 
        username: '' // 当前登录用户
      }
    },
    methods: {
      // 退出登录
      logoutUser () {
        // 清空sessionStorage
        window.sessionStorage.clear()
        this.$router.push('/login')
        this.$message.success('退出成功')
      },
      // 折叠或展开菜单
      toggleCollapse(){
        this.isMenuCollapsed = !this.isMenuCollapsed
      },
      // 保存当前激活链接
      saveActivePath(path){ 
        this.activePath = path
        window.sessionStorage.setItem('activePath', path)
      }, 
    },
    // 生命钩子
    created(){
      this.activePath = window.sessionStorage.getItem('activePath')
      this.username = window.sessionStorage.getItem('username')
    }
  }
</script>

<style lang="less" scoped>
  .home-container {
    height: 100%;
  }
  .el-header {
    background-color: #373d41;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-left: 15px;
    padding-right: 0;
    color: #fff;
    font-size: 20px;
    > div {
      display: flex;
      align-items: center;
    }
  }
  .el-aside {
    background-color: #333744;
    .toggle-button {
      width: 100%;
      background-color: #555a6d;
      font-size: 16px;
      line-height: 50px;
      text-align: center;
      color: #fff;
      letter-spacing: 0.2em;
      cursor: pointer;  
    }
    .el-menu {
      border-right: none;
    }
  }
  .el-main {
    background-color: #EAEDF1;
  }
  .el-dropdown {
    padding: 0 25px;
    display: flex;
    min-width: 50px;
    height: 60px;
  }
  .el-dropdown:hover {
    background: #4A5064;
  }
  .el-dropdown-link {
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    span {
      color: #fff;
    }
  }
</style>
  
